<template>
  <div class="box">
    <h2>A组件,{{ count }}</h2>
    <el-button type="primary" size="default" @click="handlePlus">
      数字+
    </el-button>
    <div v-for="item in goods">
      商品名称{{ item.name }} 价格{{ item.price }}
    </div>
  </div>
</template>

<script>
export default {
  computed: {
    count() {
      return this.$store.state.counter.num; //必须在computed中提取state数据
    },
    goods() {
      return this.$store.state.goods.goods;
    },
  },
  methods: {
    handlePlus() {
      this.$store.commit("counter/increment"); //触发mutation进而改变state
    },
  },
};
</script>

<style lang="scss" scoped>
.box {
  border: 1px solid #333;
  height: 500px;
  width: 50%;
}
</style>
